/* 图纸*/
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入产品名称" v-model="queryParam.productName"></a-input>
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <a-button @click="myHandleAdd" type="primary" icon="plus">新增</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="{ x: 1600, y: 500 }"
            :loading="loading"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => myhandleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <span slot="unqualifiedStock" slot-scope="text, record">
              <a-tag color="#87d068" v-if="record.unqualifiedStock == 0">合格</a-tag>
              <a-tag color="#f50" v-else>不合格</a-tag>
            </span>
            <span slot="cad" slot-scope="text, record">
              <a @click="myhandleExportXls('CAD', record.cad)" v-if="record.cad != null">下载</a>
              <span v-else>当前未上传</span>
            </span>
            <span slot="remark" slot-scope="text, record">
              <a-tooltip>
                <template slot="title">
                  {{ record.remark }}
                </template>
                <div>{{ record.remark | ellipsis(10) }}</div>
              </a-tooltip>
            </span>
            <template slot="customRenderStatus" slot-scope="status">
              <a-tag v-if="status == '0'" color="red">未审核</a-tag>
              <a-tag v-if="status == '1'" color="green">已审核</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <addDrawing ref="modalForm" @ok="modalFormOk"></addDrawing>
      </a-card>
    </a-col>
  </a-row>
</template>
<!--power by jisheng hua-->
<script>
import addDrawing from './modules/addDrawing'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { BillListMixin } from './mixins/BillListMixin'
import JDate from '@/components/jeecg/JDate'
import { downFile, deleteAction } from '@/api/manage'
import Vue from 'vue'
export default {
  name: 'Drawing',
  mixins: [JeecgListMixin, BillListMixin],
  components: {
    addDrawing,
    JDate
  },
  //文字溢出隐藏
  filters: {
    ellipsis(val, length) {
      if (val) {
        if (val.length > length) {
          return val.substring(0, length) + '...'
        } else {
          return val
        }
      }
    }
  },
  data() {
    return {
      // 查询条件
      queryParam: {},
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      // 表头
      columns: [
        // { title: '序号', dataIndex: 'serialNo', width: 100, align: 'center' },
        { title: '序号', dataIndex: 'serialNo', width: 100, align: 'center' },
        { title: '客户名', dataIndex: 'customerName', width: 100, align: 'center' },
        { title: '产品名称', dataIndex: 'productName', width: 100, align: 'center' },
        { title: '规格', dataIndex: 'specifications', width: 100, align: 'center' },
        { title: 'CAD下载', dataIndex: 'cad', width: 100, align: 'center', scopedSlots: { customRender: 'cad' } },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 100,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/blueprintInfo/getPage',
        exportXlsUrl: '/systemConfig/static',
        delete: '/blueprintInfo'
      }
    }
  },
  computed: {},
  created() {},
  methods: {
    myhandleExportXls(fileName, getUrl) {
      if (!fileName || typeof fileName != 'string') {
        fileName = '导出文件'
      }
      console.log(this.model)
      downFile(this.url.exportXlsUrl + '/' + getUrl).then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), getUrl)
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', getUrl)
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    myhandleDelete: function(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      console.log(id)
      deleteAction(that.url.delete + '/' + id).then(res => {
        if (res.code === 200 || res.code === 10000) {
          this.$message.success('删除成功')
          that.loadData()
        } else {
          that.$message.warning(res.data.message)
        }
      })
    }
  }
}
</script>
<style scoped>
/** Button按钮间距 */
.table-operator .ant-btn {
  margin: 0 8px 8px 0;
}
@import '~@assets/less/common.less';
</style>
